home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / STRINGS.SWG / 0069_Getting Initials.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  2KB  |  51 lines

  1. {
  2. > 2: And with a string I want to read a specific string and
  3. > get the first to letter of the 1st and last names.
  4. > So for example: Mike Enos ==> ME-DATA.DAT.
  5. >
  6. > Function GetDatName : String;
  7. [deleted]
  8.  
  9.  To get the first letter of a surname, it might be better to scan
  10.  from the end of the string -- in case the person also uses their
  11.  middle name or initial...
  12. }
  13.  
  14. PROGRAM Monogram;
  15.  
  16. VAR
  17.   PersonName  : STRING[64];             (* person's name(s)   *)
  18.   FileName    : STRING[12];             (* file name          *)
  19.   Index       : WORD;                   (* character pointer  *)
  20.  
  21. BEGIN
  22.   FileName := '??-DATA.DAT';                (* common file name   *)
  23.  
  24.   PersonName := 'Jack B. Nimble';           (* example name       *)
  25.  
  26.   (* the person's name MUST contain at least one space...         *)
  27.  
  28.   IF (Length(PersonName)=0) OR (Pos(' ',PersonName)=0) THEN BEGIN
  29.     WriteLn; WriteLn ('First AND Last names, please...');
  30.     Halt(1);
  31.   END;
  32.  
  33.   (* assume there's no leading white spaces...                    *)
  34.  
  35.   FileName[1] := UpCase (PersonName[1]);    (* pick up 1st char   *)
  36.  
  37.   (* scan from the end of PersonName, looking for white space...  *)
  38.  
  39.   Index := Length (PersonName);
  40.   WHILE (Index > 0) AND (PersonName[Index] > ' ') DO DEC (Index);
  41.  
  42.   INC (Index);    (* ... 'cause we went one too many              *)
  43.  
  44.   FileName[2] := PersonName[Index];   (* get 1st char of surname  *)
  45.  
  46.   WriteLn;
  47.   WriteLn ('File name for "',PersonName,'" is ',FileName);
  48.   WriteLn;
  49.  
  50. END.
  51.